package com.xiaohe66.web.infrastructure.domain.adapter.birth;

import com.xiaohe66.web.domain.birth.agg.Birthday;
import com.xiaohe66.web.domain.birth.value.BirthdayId;
import com.xiaohe66.web.domain.birth.value.BirthdayName;
import com.xiaohe66.web.domain.birth.value.BirthdayType;
import com.xiaohe66.web.infrastructure.domain.adapter.DataConverter;

import java.time.LocalDate;

/**
 * @author xiaohe
 * @since 2023.07.12 17:06
 */
public interface BirthdayConverter extends DataConverter {

    default BirthdayId newId(Long value) {
        return ifPresent(value, BirthdayId::new);
    }

    default BirthdayName newBirthdayName(String value) {
        return ifPresent(value, BirthdayName::new);
    }

    default BirthdayType newBirthdayType(int value) {
        return ifPresent(value, BirthdayType::valueOf);
    }

    default LocalDate asNextBirthdayDate(Birthday birthday) {
        return birthday.toBirthdayValue().nextBirthday().toDate();
    }

}
